import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_widgets/resources/kq_theme_colors.dart';
import 'package:kq_flutter_widgets/widgets/button/kq_head_button.dart';
import 'package:kq_flutter_widgets/widgets/drawer/kq_drawer.dart';
import 'package:kq_flutter_widgets/widgets/tabView/kq_tab_view.dart';
import 'package:kq_flutter_widgets/widgets/titleBar/kq_title_bar.dart';
import 'package:kq_flutter_widgets_example/resources/kq_images.dart';

class KqDrawerDemo extends StatefulWidget {
  const KqDrawerDemo({super.key});

  @override
  State<KqDrawerDemo> createState() => _KqDrawerDemoState();
}

class _KqDrawerDemoState extends State<KqDrawerDemo> {
  GlobalKey<ScaffoldState> globalKey = GlobalKey();

  List drawerData = [
    {"enable": "1", "title": "计划单号", "titleId": "planNo"},
    {"enable": "1", "title": "任务单号", "titleId": "taskNo"},
    {"enable": "1", "title": "订单编号", "titleId": "orderNo"},
    {"enable": "1", "title": "产品名称", "titleId": "productName"},
    {"enable": "1", "title": "产品编号", "titleId": "partNum"},
    {"enable": "1", "title": "模具编号", "titleId": "moldNo"},
    {"enable": "1", "title": "模具名称", "titleId": "moldName"},
    {"enable": "1", "title": "产品重量", "titleId": "weight"},
    {"enable": "1", "title": "材料编号", "titleId": "materialId"},
    {"enable": "1", "title": "材料名称", "titleId": "materialName"},
    {"enable": "1", "title": "色粉编号", "titleId": "cpId"},
    {"enable": "1", "title": "色粉名称", "titleId": "cpName"},
    {"enable": "1", "title": "客户名称", "titleId": "customerName"},
    {"enable": "1", "title": "生产数量", "titleId": "productNum"},
    {"enable": "1", "title": "合模数", "titleId": "workNum"},
    {"enable": "1", "title": "任务数量", "titleId": "shotNum"},
    {"enable": "1", "title": "当班实际生产时长", "titleId": "totalCycle"},
    {"enable": "1", "title": "班次报工差额", "titleId": "remindStockInputNum"},
    {"enable": "1", "title": "任务剩余报工数量", "titleId": "remindPlanNum"},
    {"enable": "1", "title": "报工人员", "titleId": "reportPersonName"},
    {"enable": "1", "title": "班次理论产量", "titleId": "goalTourNum"},
    {"enable": "1", "title": "班次达成率", "titleId": "tourNumGoalRate"},
    {"enable": "1", "title": "单模产量(标准/实际)", "titleId": "output"},
    {"enable": "1", "title": "成本", "titleId": "price"},
    {"enable": "1", "title": "标准周期", "titleId": "cycleTime"},
    {"enable": "1", "title": "产品标准周期", "titleId": "productCycleTime"},
    {"enable": "1", "title": "模具标准周期", "titleId": "moldCycleTime"},
    {"enable": "1", "title": "平均周期", "titleId": "perCycle"},
    {"enable": "1", "title": "生产日期", "titleId": "workTime"},
    {"enable": "1", "title": "实际开工时间", "titleId": "taskStartTime"},
    {"enable": "1", "title": "实际完工时间", "titleId": "taskCompTime"},
    {"enable": "1", "title": "报合格数量", "titleId": "standardNum"},
    {"enable": "1", "title": "次品数量", "titleId": "defectiveNum"},
    {"enable": "1", "title": "班次良品率", "titleId": "nonDefectiveRate"},
    {"enable": "1", "title": "班次次品率", "titleId": "defectiveRate"},
    {"enable": "1", "title": "当班计件工资", "titleId": "pieceWageSum"},
    {"enable": "1", "title": "班次", "titleId": "tour"},
    {"enable": "1", "title": "生产人员", "titleId": "realName"}
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: KqHeadBar(
        headTitle: '抽屉',
        back: () {
          Get.back();
        },
        actions: Row(
          children: [
            KqHeadButton(
              buttonType: KqHeadButtonType.icon,
              widget: Image.asset(
                KqImages.demoEditor,
                width: 20,
                height: 20,
              ),
              onTap: () {
                globalKey.currentState?.openDrawer();
              },
            ),
            KqHeadButton(
              buttonType: KqHeadButtonType.icon,
              widget: Image.asset(
                KqImages.demoEditor,
                width: 20,
                height: 20,
              ),
              onTap: () {
                globalKey.currentState?.openEndDrawer();
              },
            )
          ],
        ),
      ),
      key: globalKey,
      drawer: KqDrawer(
          drawerPositionType: DrawerPositionType.drawerPositionTypeLeft,
          drawerGlobalKey: globalKey,
          drawerData: () => drawerData,
          drawItemContent: (data) {
            return data['title'] ?? '';
          },
          drawItemSelectStatus: (data) {
            var enable = data['enable'];
            if (enable == '1') {
              return true;
            }
            return false;
          },
          onTap: (state, data) {
            var enable = data['enable'];
            if (enable == '1') {
              data['enable'] = '0';
            } else {
              data['enable'] = '1';
            }
          },
          onDrop: (data) {
            drawerData = data;
          },
          customBottomWidget: (state, data) => const KqTabView(
                titles: ['重置', '确定'],
                colorTypes: [ColorType.lineBlue, ColorType.fillBlue],
              ),
          isSupportDrag: false),
      endDrawer: KqDrawer(
          drawerGlobalKey: globalKey,
          drawerData: () => drawerData,
          drawItemContent: (data) {
            return data['title'] ?? '';
          },
          drawItemSelectStatus: (data) {
            var enable = data['enable'];
            if (enable == '1') {
              return true;
            }
            return false;
          },
          onTap: (state, data) {
            var enable = data['enable'];
            if (enable == '1') {
              data['enable'] = '0';
            } else {
              data['enable'] = '1';
            }
            state.reload();
          },
          onDrop: (data) {
            drawerData = data;
          },
          customBottomWidget: (state, data) => const KqTabView(
                titles: ['重置', '确定'],
                colorTypes: [ColorType.lineBlue, ColorType.fillBlue],
              ),
          isSupportDrag: false),
    );
  }
}
